package Fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.zelonghu.testgps.NavigationHost;
import com.example.zelonghu.testgps.R;

import org.w3c.dom.Text;

import Preferences.Preferences;

/**
 * @author zelonghu QQ:1032006226
 * @name testGPS2
 * @class name：Fragment
 * @class describe
 * @time 2019/5/28 4:05 PM
 * @change
 * @chang time
 * @class describe
 */
public class MeFragment extends Fragment implements View.OnClickListener {
    Button loginbutton = null;
    Button logoutbutton = null;
    Button exitbuton;
    TextView introduceTW = null;
    RelativeLayout mytask_rl;
    TextView usernameTW = null;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.testgps2_fragment_me,container,false);
        loginbutton = (Button)view.findViewById(R.id.loginbutton);
        loginbutton.setOnClickListener(this);
        logoutbutton = (Button)view.findViewById(R.id.logoutbutton);
        logoutbutton.setOnClickListener(this);
        introduceTW = (TextView)view.findViewById(R.id.userDescription);
        usernameTW = (TextView)view.findViewById(R.id.userName);
        mytask_rl = (RelativeLayout)view.findViewById(R.id.fragment_me_mytask_rl);
        mytask_rl.setOnClickListener(this);

        exitbuton = (Button)view.findViewById(R.id.mefragment_btn_exit);
        exitbuton.setOnClickListener(this);
        Log.i("hello","hello");

        //更新图像
        Bundle bundle = new Preferences(getContext()).get_login_info();
        Log.i("hello",bundle.toString());
        String imagepath = bundle.getString("imagepath");
        String username = bundle.getString("username");
        String userintroduce = bundle.getString("userintroduce");

        Log.i("hello",imagepath+username+userintroduce);
        if(imagepath.length()!=0){
            //多线程搞定图像显示
        }
        if(userintroduce.length()!=0){

            introduceTW.setText(userintroduce);
        }
        if(username.length()!=0){
            usernameTW.setText(username);
        }

        return view;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.loginbutton:
                //点击登录按钮，进入到登录端口
                ((NavigationHost)getActivity()).navigateTo(new LoginFragment(),true);

                break;
            case R.id.logoutbutton:

                //首先退出这个Fragme
                getFragmentManager().popBackStack();
                //重新绘图

                //回到这个页面
                ((NavigationHost)getActivity()).navigateTo(new MeFragment(),true);

                break;
            case R.id.fragment_me_mytask_rl:
                Log.i("clice","click my task");
                //todo 跳转到我的任务页面
                ((NavigationHost)getActivity()).navigateTo(new TaskFragment(),true);
                break;
            case R.id.mefragment_btn_exit:
                getFragmentManager().popBackStack();
                break;
        }
    }
}

